package com.mida.app.knw.service.impl;

import com.mida.app.knw.service.MdmService;
import com.mida.dms.mdm.api.provider.IAuthApi;
import com.mida.dms.mdm.api.provider.IBusinessUnitApi;
import com.mida.dms.mdm.api.provider.IEmployeeInfoApi;
import com.mida.dms.mdm.api.provider.IOrgInfoApi;
import com.mida.dms.mdm.dto.UserDto;
import com.mida.dms.mdm.vo.provider.BaseOrgInfoVo;
import com.mida.dms.mdm.vo.provider.BusinessUnitVo;
import com.mida.dms.mdm.vo.provider.EmployeeInfoVo;
import com.mida.tool.common.result.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MdmServiceImpl implements MdmService {

    /**
     * 员工相关查询feign接口
     */
    @Autowired
    private IEmployeeInfoApi iEmployeeInfoApi;


    @Autowired
    private IBusinessUnitApi iBusinessUnitApi;

    /**
     * 集团、医院、科室相关查询feign接口
     */
    @Autowired
    private IOrgInfoApi iOrgInfoApi;

    /**
     * 获取当前用户信息
     */
    @Autowired
    private IAuthApi iAuthApi;

    /**
     * 1、根据当前用户员工soid查询医院
     *
     * @return
     */
    @Override
    public ListResult<List<BaseOrgInfoVo>> findHospitalByEmployeeSoid(Long employeeSoid1) {
        return iOrgInfoApi.findHospitalByEmployeeSoid(employeeSoid1);
    }

    /**
     * 2、查询医院下的所有业务单元
     *
     * @param hospitalSoid 医院soid
     * @param buTypeCode   业务单元类型
     * @param search       检索条件:名称，代码，拼音码，五笔码
     */
    @Override
    public ListResult<List<BusinessUnitVo>> findBusinessUnitListUnderHospital(Long hospitalSoid, Long buTypeCode, String search) {
        return iBusinessUnitApi.findBusinessUnitListUnderHospital(hospitalSoid, buTypeCode, search);
    }

    /**
     * 3.1根据医院soid模糊查询当前医院下员工信息
     *
     * @param search      检索条件:工号,名称,拼音码，五笔码，
     * @param orgInfoSoid 组织soid （医院soid）
     * @param orgInfoType 组织类型:集团-2585、医院-2586、科室-2587
     * @return
     */
    @Override
    public ListResult<List<EmployeeInfoVo>> findListByOrgSoid(Long orgInfoSoid, long orgInfoType, String search) {
        return iEmployeeInfoApi.findListByOrgSoid(orgInfoSoid, orgInfoType, search);
    }

    /**
     * 3.2 根据业务单元soid模糊查询员工信息
     *
     * @param search              检索条件:工号,名称,拼音码，五笔码，
     * @param businessUnitSoidStr 业务单元soid集合
     * @return
     */
    @Override
    public ListResult<List<EmployeeInfoVo>> findListByBusinessUnitSoidList(String businessUnitSoidStr, String search) {
        return iEmployeeInfoApi.findListByBusinessUnitSoidList(businessUnitSoidStr, search);
    }

    /**
     * 根据组织soid查询组织
     *
     * @param orgInfoSoid     组织soid
     * @param isIncludeDelete 是否包含已删除的数据(回显的时候需要用到)
     * @return
     */
    @Override
    public ListResult<BaseOrgInfoVo> findOrgByOrgInfoSoid(Long orgInfoSoid, boolean isIncludeDelete) {
        return iOrgInfoApi.findOrgByOrgInfoSoid(orgInfoSoid, false);
    }

    /**
     * 根据soid查询业务单元
     *
     * @param businessUnitSoid 业务单元soid
     * @param isIncludeDelete  是否包含已删除的数据(回显的时候需要用到),true-包含，false-不包含
     */
    @Override
    public ListResult<BusinessUnitVo> findBusinessUnitBySoid(Long businessUnitSoid, boolean isIncludeDelete) {
        return iBusinessUnitApi.findBusinessUnitBySoid(businessUnitSoid, false);
    }

    /**
     * 根据员工soid查询
     *
     * @param employeeSoid    员工soid
     * @param isIncludeDelete 是否包含已删除、已停用的记录
     */
    @Override
    public ListResult<EmployeeInfoVo> findOneBySoid(Long employeeSoid, boolean isIncludeDelete) {
        return iEmployeeInfoApi.findOneBySoid(employeeSoid, false);
    }

    /**
     * 查询员工所属的所有业务单元
     * @param employeeSoid 员工soid
     * @param buTypeCode 业务单元类型soid 非必填 2951-临床业务单元，2954-护理业务单元，3572-医技业务单元
     * @return
     */
    @Override
    public ListResult<List<BusinessUnitVo>> findBusinessUnitListByEmployeeSoid(Long employeeSoid, Long buTypeCode) {
        return iBusinessUnitApi.findBusinessUnitListByEmployeeSoid(employeeSoid,null);
    }
    /**
     * 查询当前登录用户信息
     * @return UserDto
     */
    @Override
    public ListResult<UserDto> getLoginUserInfo() {

        ListResult<UserDto> loginUserInfo = iAuthApi.getLoginUserInfo();
        return loginUserInfo;
    }

}
